#include "Kchangement.h"


Kchangement::Kchangement(int Korigine, int Diminution, int Palier, int NbMachines, int best)
{
	_cptDiminuant = 0;
	_resultDiminuant = best;
	K = Korigine;
	_diminution = Diminution;
	_nbMachine = NbMachines;
	_palier = Palier;
	_heuristique = new Heuristique(_nbMachine);
	this->Korigine = Korigine;
}

// Remise a zero des variable
void Kchangement::RAZVar(int best)
{
	_cptDiminuant = 0;
	_resultDiminuant = best;
	K = Korigine;
}


Kchangement::~Kchangement(void)
{
}

vector<int> Kchangement::Descente(vector<int> assignments, DataParser *data)
{
	assignmentsBack = assignments;
	for(int i = 0;i<K;i++)
	{
		int random = rand()%assignments.size();
		assignments[random]  = _heuristique->GetNumMachine();
	}
	return assignments;
}

void Kchangement::Diminuant(int resultat)
{
	if(resultat == _resultDiminuant && K > 1)
	{
		_cptDiminuant += 1;

		if(_cptDiminuant == _palier)
		{
			K -= _diminution;
			_cptDiminuant = 0;
		}
	}
	else
	{
		_resultDiminuant = resultat;
		_cptDiminuant = 0;
	}
}

void Kchangement::DiminuantAugmentant(int resultat)
{
	if(resultat == _resultDiminuant && K > 1)
	{
		_cptDiminuant += 1;

		if(_cptDiminuant == _palier)
		{
			K -= _diminution;
			_cptDiminuant = 0;
		}
	}
	else
	{
		if(resultat == _resultDiminuant)
		{
			_cptDiminuant += 1;

			if(_cptDiminuant == (_palier))
			{
				K = Korigine;
				_cptDiminuant = 0;
			}
		}
		else
		{
			_resultDiminuant = resultat;
			_cptDiminuant = 0;
		}
	}
}

void Kchangement::AugmentantDiminuant(int resultat)
{
	if(resultat == _resultDiminuant && K < Korigine)
	{
		_cptDiminuant += 1;

		if(_cptDiminuant == _palier)
		{
			K += _diminution;
			_cptDiminuant = 0;
		}
	}
	else
	{
			_resultDiminuant = resultat;
			_cptDiminuant = 0;
			K=1;
	}
}